/**
 * @author		Sergey Suzdalskiy
 * @e-mail:		sergey.suzdalskiy@gmail.com
 */
package ua.kiev.gcore.ui.controls
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.text.TextField;
	
	public class ProgressBarLabel extends Sprite
	{
		private var backGround:MovieClip;
		private var textField:TextField;
		private var _value:int;
		
		public function ProgressBarLabel(backGround:MovieClip)
		{
			super();
			if(backGround.hasOwnProperty("bg")){
				this.backGround = backGround["bg"];
			}else{
				this.backGround = backGround;
			}
			
			if(backGround.hasOwnProperty("label") && (backGround["label"] is TextField)){
				textField = backGround["label"];
			}else{
				textField = new TextField();
			}
			
			this.backGround.gotoAndStop(1);
			addChild(this.backGround);
			addChild(textField);
		}
		
		/** i = [0;100] **/
		public function set value(i:int):void{
			if(i != value){
				if((i > 0)&&(i<101)){
					if(i <= 0){
						i = 1;
					}
					if(i > 101){
						i = 101;
					}
				}
				_value = i;
				if(backGround){
					backGround.gotoAndStop(value);					
				}
			}
		}
		
		public function get value():int{
			return _value;
		}
		
		public function set label(value:String):void{
			if((value) && (textField)){
				textField.text = value;
			}
			
		}
		public function get label():String{
			if(textField){
				return textField.text;
			}
			
			return new String();
		}
	}
}